package oj;

/**
 * @author 郝文雪
 * @date 2022/7/16 16:26
 * @Description 搜索二维矩阵Ⅱ
 *
 */
public class LC240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int n=matrix.length;
        int m=matrix[0].length;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int l=0;
                int r=m-1;
                while(l<=r){
                    int mid=(l+r)/2;
                    if(matrix[i][mid]>target){
                        r=mid-1;
                    }else if(matrix[i][mid]<target){
                        l=mid+1;
                    }else{
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
